package com.fysports.web.api;

import com.jfinal.aop.Clear;
import com.jfinal.log.Log;
import com.fysports.web.kit.commons.PathBizKit;
import com.fysports.web.kit.commons.StringKit;
import com.fysports.web.model.app.AppFeedback;
import com.fysports.web.model.app.AppUpdate;
import com.fysports.web.module.view.JsonView;
import com.fysports.web.module.view.OperateType;


/**
 * 移动端的系统设置
 * 意见反馈
 * 系统更新
 * Created by konbluesky
 * Date : 14-9-15 下午4:39
 * Project : JdmData_WebServer
 */
@Clear
public class APISystemSettingController extends APIController {
    private final static Log logger = Log.getLog(APISystemSettingController.class);


    public void index() {
    }


    /**
     * 保存用户反馈
     */
    public void feedback() {
        boolean status = false;
        try {
            String userid = getPara(CONST_USERUUID, "");
            if (StringKit.isBlank(userid)) {
                //TODO 从请求头或者cookie中获取
            }
            String text = getPara("text");

            AppFeedback smf = new AppFeedback();
            smf.set(AppFeedback.COL_TEXT, text);
            smf.set(AppFeedback.COL_USERUUID, userid);
            status = smf.save();
            if (status) {
                renderJson(new JsonView(status, OperateType.OPERATE_SUCCESS));
                return;
            }
        }
        catch (Exception e) {
            logger.error("API意见反馈失败：", e);
            e.printStackTrace();
        }
        renderJson(new JsonView(status, OperateType.OPERATE_FAIL));
    }


    public void update() {
        setAttr("m", AppUpdate.dao.searchFirst(AppUpdate.COL_LIVEFLAG, 1));
        renderXml(PathBizKit.getProtocolPath("/MobileAppVersion.xml"));
    }

}
